import pageination from '../../components/pageination/pageination.vue'
import urls from "../../common/js/api_url_array";
export default {
  data() {
    return {
      //数据
      search: '',//搜索信息
      total: 0, //总条数
      page: 1, //当前页
      size: 10, //每页显示条数
      //expertProjectWorkLogList: [],  //专家项目列表
      cooperativeProjectList: [], //合作项目
      baseTotal: 0, //普通总条数
      basePage: 1, //普通当前页
      baseSize: 10, //普通每页显示条数
      tempWorkLogProjectId: null,
      tempWorkLogExpertId: null,
      expertWorkLogList: [], //专家工作日志列表
      validate: {}, // 校验对象
      expertProjectWorkLog: {}, //工作日志对象
      picture: '', // img
      modelShow: false,
      ProjectModelShow: false,
      demandModelShow: false,
      WorkModelShow: false,
      uploadNum: 0,
      FileUpload: [],
      curId: 0,
      userId: this.get("userInfo").id,
      tableData: [] ,   // 列表
      projectId: '' // 新增xiangmu id  this.validate.resetForm();
    }
  },
  components: {
    pageination
  },
  created() { //调用方法
    let that = this;

  },
  mounted() {
    //加载表单验证
    this.validate = $("#logForm").validate({
      ignore: [],
      rules: {
        theme: { // 主题
          required: true,
          maxlength: 50
        },
        beginTime: { // 开始时间
          required: true
        },
        endTime: { // 结束时间
          required: true
        },
        content: { // 事由
          required: true,
          maxlength: 100
        },
        position: { // 地址
          required: true,
          maxlength: 50
        },
        picture: { // 图片
          maxlength: 150
        }
      },
      messages: {
        theme: { // 主题
          required: "请输入主题",
          maxlength: "请输入长度小于50"
        },
        beginTime: { // 开始时间
          required: "请选择时间"
        },
        endTime: { // 结束时间
          required: "请选择结束时间"
        },
        content: { // 事由
          required: "请输入事由",
          maxlength: "事由最多输入100个字"
        },
        position: { // 地址
          required: "请输入地点",
          maxlength: "地点最多输入50个字"
        },
        picture: { // 图片
          maxlength: "请选择长度小于150"
        }
      },
//			errorElement: "em",
//			errorPlacement: function(error, element) {
//				error.appendTo(element.parents(".error-box").children(".error-msg"));
//			}
    });
  },
  methods: { //写函数方法
    //查询当前专家工作记录日志
    getData: function () {
      let that = this;
      /*let name = $('#search').val();
      that.$post(
        that.urls.getLog,
        {"userId": that.userId, "baseName": name, "pageNum": that.page,
          "pageSize": that.size}
      )
        .then(function(res) {
          if(res.success) {
            that.tableData = res.pageInfo.list;
            that.total = res.pageInfo.total;
            that.page = res.pageInfo.pageNum;
          }
        })*/

      that.$post(
        //that.urls.getCurrentExpertProjectWorkLogPageInfo,
        that.urls.getCurrentExpertCooperativeProjectPageInfo,
        {
          "search": that.search,
          "pageNum": that.page,
          "pageSize": that.size
        }
      )
      .then(function(res) {
        if(res.success) {
          //that.expertProjectWorkLogList = res.pageInfo.list;
          that.cooperativeProjectList = res.pageInfo.list;
          that.total = res.pageInfo.total;
          that.page = res.pageInfo.pageNum;
        }
      })
    },
    //查询专家工作记录日志
    getExpertWorkLog: function (projectId, expertId) {
      if (projectId == null || expertId == null) {
        return;
      }
      let that = this;
      that.$post(
        that.urls.getExpertWorkLogPageInfo,
        {
          "projectId": projectId,
          "expertId": expertId,
          "pageNum": that.basePage,
          "pageSize": that.baseSize
        }
      )
      .then(function(res) {
        if(res.success) {
          that.expertWorkLogList = res.pageInfo.list;
          that.baseTotal = res.pageInfo.total;
          that.basePage = res.pageInfo.pageNum;
        }
      })
    },
    //查询所有专家工作记录日志
    getAllExpertWorkLog: function (projectId, expertId) {
      if (projectId == null || expertId == null) {
        return;
      }
      let that = this;
      that.$post(
        that.urls.getAllExpertWorkLog,
        {
          "projectId": projectId,
          "expertId": expertId
        }
      )
      .then(function(res) {
        if(res.success) {
          that.expertWorkLogList = res.data;
        }
      })
    },
    // 新增log 提交
    subLog: function () {
      let that = this;
      /*let   dataObj = {"beginTime": $('#beginTime').val(), "position": $('#position').val(),
        "theme" : $('#theme').val(), "picture": that.picture};
      dataObj.projectId = that.projectId;
      dataObj.expertId = that.userId;*/
      let flg = that.validate.form();
      if(flg) {
        let dataObj = that.combinationFormObject(that.validate.currentForm);
        if (dataObj.picture != null && dataObj.picture != "") {
          //因为小程序添加了上传图片前缀，此处为了数据保持一致因此也添加了完整地址，注意：本平台其他地址都无前缀
          dataObj.picture = that.urls.baseUrl + dataObj.picture;
        }
        that.$post(
          that.urls.addExpertWorkLog,
          dataObj
        )
        .then(function(res) {
          let msg = "";
          if(res.success) {
            msg = "编写日志成功！";
            that.getData(); //重新渲染数据
            that.ProjectModelShow = false;
          } else {
            msg = "编写日志失败！";
          }
          layer.msg(msg, {
            time: 3000, //3s后自动关闭
          });
        })
      }
    },
    //页码切换执行方法
    pageFn: function(val, pid) {
      this.page = parseInt(val);
      this.getData();
      //此处调列表数据接口
    },
    //页码切换执行方法
    basePageFn: function(val, pid) {
      this.basePage = parseInt(val);
      this.getExpertWorkLog(this.tempWorkLogProjectId,this.tempWorkLogExpertId);
      //此处调列表数据接口
    },
    /**返回子组件用户选择的一页显示条数**/
    obtainChild: function(data) {
      this.row = data;
    },
    touchOffIdInput(n) {
      this.uploadNum = n;
      if(n == 1) {
        $("#handIdFront").click();
      }
    },
    //预览
    preview: function(url,msg) {
      if (url == null || url == "") {
        if (msg == null || msg == "") {
          msg = "附件";
        }
        layer.msg("暂无" + msg + "！");
      } else {
        window.open(this.urls.baseUrl + url);
      }
    },
    preview2: function(url,msg) {
      if (url == null || url == "") {
        if (msg == null || msg == "") {
          msg = "附件";
        }
        layer.msg("暂无" + msg + "！");
      } else {
        window.open(url);
      }
    },
    /**文件上传(多文件)js**/
    idFrontImg: function(event) {
      let that = this;
      let files = event.currentTarget.files;
      if (!that.fileGlobalFilter(files)) {
        return;
      }
      let formData = new FormData();
      for(let i = 0, len = files.length; i < len; i++) {
        formData.append('fileNames', files[i]);
      }
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data;boundary = ' + new Date().getTime()
        }
      };
      that.$post(
        that.urls.upload,
        formData,
        config
      )
        .then(function(res) {
          if(res.success) {
            let fileInfo = res.data[0];
            /*that.expertProjectWorkLog.picture = fileInfo.url;*/
            $("input[name='picture']").val(fileInfo.url);
            $("img#showHandIdFront").attr("src",that.urls.baseUrl + fileInfo.url);
            $("img#showHandIdFront").css("display","block");
          }
        })
      console.log(that.FileUpload )
    },

    //项目结题模态框
    projectDetails: function(projectId,expertId) {
      let that = this;
      if (projectId == null || expertId == null) {
        return;
      }
      /*that.projectId = id;*/
      that.expertProjectWorkLog = {};
      //清空表单校验提示
      $("#logForm").validate().resetForm();
      //清空表单数据
      $("input[type='reset']").trigger("click");
      $("img#showHandIdFront").css("display","none");
      $("img#showHandIdFront").attr("src","");
      that.expertProjectWorkLog.projectId = projectId;
      that.expertProjectWorkLog.expertId = expertId;
      that.ProjectModelShow = true;
    },
    //查看
    demand: function(projectId,expertId) {
      /*let that = this;
      that.logData = [];
      that.$post(
        that.urls.getLogPage,
        {"pageNum": that.page,
          "pageSize": 9999999, "projectId": id}
      )
        .then(function(res) {
          if(res.success) {
            that.logData = res.pageInfo.list;
          }
        })*/
      this.baseTotal = 0; //普通总条数
      this.basePage = 1; //普通当前页
      this.baseSize = 10; //普通每页显示条数
      this.expertWorkLogList = [];
      this.tempWorkLogProjectId = projectId;
      this.tempWorkLogExpertId = expertId;
      //this.getExpertWorkLog(projectId,expertId);
      this.demandModelShow = true;
    },
    timeChange: function(event) {
      $("input[name='beginTime']").val(event);
      $("input[name='beginTime']").valid();
    },
    //评分标准
    rorkRecord: function(projectId,expertId) {
      //this.demand(id);
      this.expertWorkLogList = [];
      this.getAllExpertWorkLog(projectId,expertId),
      this.demandModelShow = false;
      this.WorkModelShow = true;
    },
    //关闭模态框
    closeModel: function() {
      $(".secondLevelPageination .jump_page>input").val("");
      this.ProjectModelShow = false;
      this.demandModelShow = false;
    },
    closeModels: function() {
      this.WorkModelShow = false;
    },
  }
}
